Don't run preg_match() on null values #39927
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHP 8.1 has deprecated passing null as the second parameter to
preg_match()
, generating the following Deprecated notice:preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated
.What?
Avoids a PHP Deprecated notice
Why?
PHP 8.1 has deprecated passing null values to preg_match(), which is the default condition here.
How?
Check the
$block_gap
is a non-falsey value before processing it.This style is already used for this variable value further down the stack:
gutenberg/lib/block-supports/layout.php
Line 73 in 6de1698
The changes in this PR could also be written as:
both are logically the same here (although different around a 0 or false, which is not supported here due to the above mentioned code), as it's only checking to see if it contains invalid characters.
Testing Instructions
Unknown.
Have a block that does not contain the
blockGap
key:_wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) )
.Screenshots or screencast